<template>
  <div>
    <!-- 主体区域 -->
    <main>
      <div class="w1200">
        <div class="gap"></div>
        <div class="wfd">
          <div class="h160">
            <span><img src="@/assets/imgs/MCS_slices/MCS.png" alt="" /></span>
            <span class="pdl15">
              <span class="title">{{ eSubjectType.title }}</span>
              <span class="des">{{ eSubjectType.tips }}</span>
            </span>
          </div>
          <div class="h60">
            <span class="exnum">{{ iNum }}.{{ subject.title }}</span>
            <span class="labels">
              <span v-if="subject.isJt == '1'">机经</span>
              <span v-if="subject.isJt !== '1'" style="background: #7cc3d6"
                >练习题</span
              >
              <span
                style="background: #ff5e4e"
                v-if="subject.labelStyle == 'wrong-color'"
                >错题</span
              >
              <span style="background: #13bfbf" v-if="subject.isYc == '1'">本周预测</span>
              <span style="background: #99bbe4" v-if="practiceList.length>0"
                >练习{{ practiceList.length }}次</span
              >
              <span style="background: #94d0f7">{{ subject.titleNumber }}</span>
            </span>
            <Label
              v-if="subject.labelStyle != undefined"
              :df="subject.labelStyle"
              :id="subject.id"
            ></Label>
          </div>
          <!-- 录音播放区域 -->
          <div class="h121">
            <div>
              <AudioPlayer
                v-if="subject.url != null"
                :url="subject.url"
                :readyTime="readyTime"
                v-on:func="checkPlay"
              ></AudioPlayer>
            </div>
          </div>
          <!-- 单项选择 -->
          <div class="radio">
            <div class="descb">{{ subject.describe }}</div>
            <el-form>
              <el-radio-group v-model="checkedRadio">
                <div v-for="(item, index) in radio" :key="index">
                  <el-radio size="medium" :label="item.id"
                    ><span ref="options">{{ item.label }}</span></el-radio
                  >
                </div>
              </el-radio-group>
            </el-form>
          </div>
          <div class="time">
            <span v-if="isDt">答题时间：{{ s_to_hs(answerTime) }}</span>
            <span v-else>准备时间：{{ s_to_hs(readyTime) }}</span>
          </div>
        </div>
        <div class="gap"></div>
        <div class="h100">
          <div class="search-box">
            <el-button @click="$router.go(0)">重做</el-button>
            <span
              ref="answer"
              @click="seeAnswer"
              :class="isAnswerShow ? 'show_answer' : ''"
              class="seeAnswer"
              >查看答案</span
            >
            <el-input placeholder="输入内容/题目" v-model="keyword">
              <template slot="append">
                <div @click="searchSubject('listeningMCS')">搜索</div>
              </template>
            </el-input>
            <el-button class="prev" @click="goTo(last, '1', 'listeningMCS',subject.id)"
              >上一题
            </el-button>
            <el-button class="next" @click="goTo(next, '2', 'listeningMCS',subject.id)"
              >下一题
            </el-button>
            <el-button @click="addPractice()">提交</el-button>
          </div>
          <div class="answer-box" v-show="isAnswerShow">
            <div class="title">参考答案</div>
            <div class="content">{{ subject.answer }}</div>
            <div class="origin">
              <div class="origin-title">原文</div>
              <div>
                {{ subject.originalText }}
              </div>
            </div>
          </div>
        </div>
        <div class="gap"></div>
        <div class="myexercise">
          <div class="bt">我的练习</div>
          <!-- 没有练习的情况下，显示暂无数据 -->
          <div v-show="1" class="no-data" v-if="practiceList.length == 0">
            <i class="iconfont icon-wushuju"></i>
            <div style="fontsize: 1rem">暂无数据</div>
          </div>

          <ul v-else>
            <li v-for="(item, index) in practiceList" :key="index">
              <span class="avatar">
                <img v-lazy="item.image" alt="" />
              </span>
              <span class="content">
                <span>
                  {{ item.nickname }}
                  <span class="time">{{ item.updateDate | formatTM }}</span>
                </span>

                <span class="answer-history">{{ item.answer }}</span>
              </span>
            </li>
          </ul>
        </div>
      </div>
      <!-- 做题中选题抽屉 -->
      <Drawer :img="imgUrl"></Drawer>
    </main>
  </div>
</template>

<script>
import Label from '../../label'
import Drawer from '../../drawer'
import listeningUtil from "../../../../../utils/listeningUtil";
import AudioPlayer from "../../audioplayer/index";
import { sendPost } from "../../../../../utils/http";
import api from "../../../../../config/api";
export default {
  mixins: [listeningUtil],
  components: {
    Drawer,
    Label,
    AudioPlayer
  },
  data () {
    return {
      imgUrl: '',
      radio: [

      ],
      checkedRadio: {},
      isAnswerShow: false,
      iNum: '' // 题目索引号
    }
  },
  created () {
    setInterval(this.countDownReady, 1000)
    var query = this.$route.query;
    this.getData(query.id);
    this.iNum = this.$route.query.idx;
  },
  mounted () {
    sessionStorage.setItem('activeIndex', 'loged')
  },
  methods: {
      //跳转题目页面
  //跳转题目页面
    goTo (id, type, name, nowId) {
      console.log("搜索中", type, id, name, nowId)
      // 没有搜索到题
      if (id == '0') {
        if (type == '1') {
          this.$msg({
            message: '没有上一题了',
            type: 'warning'
          });
        }
        if (type == '2') {
          this.$msg({
            message: '没有下一题了',
            type: 'warning'
          });
        }
        return
        // 搜到题
      }
      else {
        if (nowId > id) {
          // console.log(nowId,id);
          this.$router.push('/listeningMCS?id=' + id + '&idx=' + (this.iNum / 1 - 1));

        } else if (nowId < id) {
          console.log(nowId, id);
          this.$router.push('/listeningMCS?id=' + id + '&idx=' + (this.iNum / 1 + 1));
        }
      }
    },
    seeAnswer () {
      this.isAnswerShow = !this.isAnswerShow
      if (this.isAnswerShow) {
        this.$refs.answer.innerText = '隐藏答案'
      } else {
        this.$refs.answer.innerText = '查看答案'
      }
    },
    getData (id) {
      var that = this
      sendPost(api.getSubjectDetails, {
        id: id,
      }).then((res) => {
        console.log(res)
        that.subject = res.data
        that.subject.content = that.subject.content
        that.eSubjectType = res.data.eSubjectType
        if (res.data.practiceList) {
          that.practiceList = res.data.practiceList
        }
        that.last = res.data.last
        that.next = res.data.next

        var op = res.data.option.split('&@#');
        for (var i = 0; i < op.length; i++) {
          var o = new Object();
          o.id = i + 1
          o.label = op[i];
          that.radio.push(o)
        }

      })
    },

    //提交作业
     addPractice () {
      var that = this;
      if (this.flag) {
        this.$msg.error("你已经作答，无需重复操作！")
        return
      }
      if (that.checkedRadio == '') {
        this.$msg.error("至少选择一个选项！")
        return
      } else {
        let answer = +that.subject.answer
        console.log(answer, that.checkedRadio);

        // 答对了
        if (answer === that.checkedRadio) {
          this.$refs.options[that.checkedRadio - 1].style.backgroundColor = '#09d4c0'
          let a = that.radio.filter(item => {
            return item.id == answer
          })
        } else {
          // 选择错误
          let b = that.radio.filter(item => {
            return item.id !== answer
          })
          this.$refs.options[that.checkedRadio - 1].style.backgroundColor = '#ff5e4e'
          this.$refs.options[answer - 1].style.backgroundColor = '#c1c1c1'
        }
      }


      that.flag = true
      // let answer = +that.subject.answer
      sendPost(api.submitAnswer, {
        id: that.$route.query.id,
        answer: that.checkedRadio,
        times: that.answerTime
      }).then((r) => {
        that.$msg({
          message: '答案提交成功',
          type: 'success'
        });


        this.refresh(that.$route.query.id);
      })
    },
  }
}
</script>

<style lang="less" scoped>
.seeAnswer {
  display: inline-block;
  background: #fffafa;
  border: 0.0625rem solid #ff5e4e;
  color: #ff5e4e;
  height: 2.5rem;
  font-size: 1.125rem;
  line-height: 2.5rem;
  border-radius: 0.3125rem;
  padding: 0 0.2875rem;
  // margin-right: 14.375rem;
  // margin-left: 7.25rem;
  cursor: pointer;
}
.show_answer {
  color: #fff;
  background-color: #ff5e4e;
}
.descb {
  height: 2.5rem;
  line-height: 2.5rem;
  padding-left: 3.125rem;
  font-size: 1.2rem;
  font-weight: bold;
  color: #333;
}
/deep/.el-tabs__active-bar {
  height: 0.25rem;
}
/deep/.el-tabs__item.is-active {
  color: #333;
  border-bottom-color: #ff5e4e;
}
/deep/.el-tabs__item:hover {
  color: #333;
}
/deep/.el-tabs__active-bar {
  background-color: #ff5e4e;
}
/deep/.el-tabs__nav-wrap::after {
  background-color: #fff;
}
/deep/.el-tabs__nav {
  padding: 0.4375rem 0;
}
/deep/.el-tabs__item {
  font-size: 1rem;
}
/deep/.el-input__inner {
  border-radius: 1.25rem;
  border-color: #c0c4cc;
}
/deep/.el-col-8 {
  margin-top: 0.75rem;
}
main {
  height: 100%;
  width: 100%;
  background-color: #eff1f4 !important;
  padding-bottom: 4.625rem;
  box-sizing: border-box;
  .w1200 {
    width: 75rem;
    margin: auto;
    background-color: #eff1f4;
    .gap {
      height: 0.75rem;
    }
    .wfd {
      background-color: #fff;
      padding: 2.5rem 2.5rem 1.875rem;
      box-sizing: border-box;
      .h160 {
        height: 10rem;
        display: flex;
        padding-right: 6.875rem;
        box-sizing: border-box;
        .pdl15 {
          padding-left: 0.9375rem;
          box-sizing: border-box;
          display: flex;
          flex-direction: column;
          .title {
            font-size: 1.25rem;
            color: #333;
            font-weight: bold;
          }
          .des {
            font-size: 1rem;
            color: #999;
            line-height: 2rem;
          }
        }
      }
      .h60 {
        height: 3.75rem;
        line-height: 3.75rem;
        padding-left: 1.25rem;
        box-sizing: border-box;
        background-color: #f7f7f7;
        display: flex;
        position: relative;
        .exnum {
          width: 45rem;
          font-size: 1rem;
          color: #666;
          overflow: hidden;
          text-overflow: ellipsis;
          white-space: nowrap;
        }
        .labels {
          display: flex;
          justify-content: flex-end;
          width: 21.25rem;
          span {
            height: 1.875rem;
            line-height: 1.875rem;
            padding: 0 0.375rem;
            box-sizing: border-box;
            background-color: #ff9b4f;
            border-radius: 0.1875rem;
            margin: 0.9375rem 0.46875rem;
            color: #fff;
            box-sizing: border-box;
          }
        }
      }
      .h121 {
        margin: 3.125rem 0 1.5625rem;
        width: 100%;
        background: #fffafa;
        border: 0.1875rem dashed #ff5e4e;
        border-bottom: 0.1875rem dashed #ff5e4e !important;
        box-sizing: border-box;
        padding: 1.25rem 1.75rem 1.6875rem;
        box-sizing: border-box;
        font-size: 1.125rem;
        color: #666;
        line-height: 2rem;
        padding-top: 2.625rem;
        div {
          display: flex;
          .iconfont {
            font-size: 1.75rem;
            color: #666;
            cursor: pointer;
          }
          span {
            margin: auto;
          }
        }
        /deep/.el-progress__text i {
          display: none;
        }
        /deep/.el-progress-bar__outer {
          width: 54.5625rem;
        }
      }
      // 单选
      .radio {
        .el-radio {
          margin-left: 3.125rem;
          white-space: pre-wrap;
          line-height: 2.1875rem;
        }
        /deep/.el-radio__input.is-checked .el-radio__inner {
          background-color: #ff5e4e;
          border-color: #ff5e4e;
        }
        /deep/.el-radio__input.is-checked + .el-radio__label {
          color: #666;
          width: 70rem;
        }
        /deep/.el-radio__label {
          font-size: 1.125rem;
        }
        /deep/.el-radio-group {
          width: 70rem;
        }
      }
      .answer-list {
        span {
          padding: 0.5rem 0.625rem;
          background-color: #ccc;
          color: #fff;
          margin-right: 1.25rem;
          font-size: 1.125rem;
          border-radius: 0.1875rem;
          cursor: pointer;
        }
      }
      .time {
        font-size: 1rem;
        font-family: Microsoft YaHei;
        font-weight: 400;
        color: #333333;
        position: relative;
        margin-top: 1.875rem;
        span {
          margin-right: 1.875rem;
        }
        .iconfont {
          font-size: 1.5rem;
          color: #ccc;
        }
        .end {
          position: absolute;
          right: -1.5rem;
          text-align: right;
        }
      }
    }
    .tishi {
      height: 10.0625rem;
      background-color: #ff5e4e;
      margin-top: 0.625rem;
      text-align: center;
      color: #fff;
      .h80 {
        height: 5rem;
        line-height: 5rem;
        font-size: 1.5rem;
      }
      .howopen {
        width: 12.5rem;
        height: 3.125rem;
        line-height: 3.125rem;
        border: 0.0625rem solid #ffffff;
        border-radius: 0.1875rem;
        margin: auto;
        font-size: 1rem;
        cursor: pointer;
      }
    }
    .myexercise {
      margin-top: 0.625rem;
      background-color: #fff;
      padding: 0 2.5rem;
      box-sizing: border-box;
      padding-bottom: 1.25rem;
      .no-data {
        width: 16.875rem;
        height: 11.25rem;
        margin: auto;
        text-align: center;
        color: #999;
        margin-bottom: 2.5rem;
        .iconfont {
          font-size: 6.875rem;
        }
      }
      .bt {
        height: 6.25rem;
        line-height: 6.25rem;
        font-size: 2rem;
        font-family: Microsoft YaHei;
        font-weight: 400;
        color: #333333;
      }
      ul {
        li {
          display: flex;
          padding-bottom: 0.625rem;
          margin-bottom: 1.2rem;
          border-bottom: 1px solid #ccc;
          .avatar {
            width: 3rem;
            height: 3rem;
            margin-right: 0.625rem;
            border-radius: 50%;
            img {
              width: 100%;
              height: 100%;
              border-radius: 50%;
            }
          }
          .content {
            flex: 1;
            font-size: 1.5rem;
            color: #333;
            display: flex;
            flex-direction: column;
            .time {
              font-size: 1rem;
              color: #999;
              margin-left: 1.875rem;
            }
            .answer-history {
              font-size: 1.125rem;
              color: #666;
              margin-top: 1rem;
            }
          }
        }
      }
    }
  }
}
.btns {
  height: 4.125rem;
  width: 25.875rem;
  margin: auto;
  margin-top: 1.25rem;
  line-height: 3.125rem;
  .el-button {
    height: 2.5rem;
    color: #ff5e4e;
    font-size: 1.125rem;
    text-align: center;
    width: 5rem;
    border-radius: 0.3125rem;
    border: 0.0625rem solid #ff5e4e;
    background-color: #fffafa;
    margin-right: 1.25rem;
  }
}
.h100 {
  padding: 1.5625rem 2.5rem;
  background-color: #fff;
  .el-button {
    height: 2.5rem;
    color: #ff5e4e;
    font-size: 1.125rem;
    text-align: center;
    width: 5rem;
    border-radius: 0.3125rem;
    border: 0.0625rem solid #ff5e4e;
    background-color: #fffafa;
    margin-right: 1.25rem;
  }
  .el-switch {
    margin-left: 1rem;
    margin-right: 0.5rem;
  }
  .el-input {
    width: 14.875rem;
    margin-left: 13rem;
    margin-right: 1.875rem;
    ::placeholder {
      font-size: 1.125rem;
      color: #cccccc;
    }
  }
  /deep/.el-input-group__append {
    padding: 0 1rem;
    background-color: #ff5e4e;
    color: #fff;
    border: 0.0625rem solid #ff5e4e;
    box-sizing: border-box;
    font-size: 1.125rem;
    cursor: pointer;
  }
  /deep/.el-input__inner {
    height: 3.125rem;
    width: 14.875rem;
    border-radius: 0.3125rem 0 0 0.3125rem;
    overflow: hidden;
    border-color: #ededed;
    border-right: none;
  }
  .prev,
  .next {
    width: 5rem;
    height: 2.5rem;
    background: #fffafa;
    border: 0.0625rem solid #ff5e4e;
    box-sizing: border-box;
    border-radius: 0.3125rem;
    color: #ff5e4e;
    margin-top: 0.8125rem;
    margin-left: 1rem;
    padding-left: 0.75rem;
    font-size: 1.125rem;
  }
  .answer-box {
    .title {
      font-size: 1.75rem;
      color: #333;
      height: 5.3125rem;
      line-height: 5.3125rem;
    }
    .content {
      font-size: 1.125rem;
      color: #666;
      line-height: 2rem;
    }
    .origin {
      font-size: 1.125rem;
      color: #666;
      line-height: 2rem;
      .origin-title {
        font-size: 1.5rem;
        color: #ccc;
        margin-top: 1.875rem;
      }
    }
  }
}
.icon-lingdang1 {
  color: #eee;
  line-height: 3.75rem;
}
.avatar {
  width: 2.5rem;
  height: 2.5rem;
  border-radius: 50%;
  display: inline-block;
  vertical-align: middle;
}
.username {
  display: inline-block;
  margin-left: 0.625rem;
  font-weight: bold;
  font-size: 1rem;
  color: #333333;
  width: 6.25rem;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.jj-bg {
  background: #ff9b4f;
}
.jj-color {
  color: #ff9b4f;
}
.lxt-bg {
  background: #7cc3d6;
}
.lxt-color {
  color: #7cc3d6;
}
.wrong-bg {
  background: #ff5e4e;
}
.wrong-color {
  color: #ff5e4e;
}
.gpzt-bg {
  background: #13bfbf;
}
.gpzt-color {
  color: #13bfbf;
}
.lxcs-bg {
  background: #99bbe4;
}
.lxcs-color {
  color: #99bbe4;
}
.ylx-bg {
  background: #94d0f7;
}
.ylx-color {
  color: #94d0f7;
}
</style>
